#pragma once

#include <YSimpleSystem/YSimpleSystem.h>
#include <minwinbase.h>

namespace ysimple_system
{

	template<typename _T>
	class YScopedLock
	{
		_T& m_lockedObject;
	public:
		YScopedLock(_T& lockedObject) : m_lockedObject(lockedObject)
		{			
			m_lockedObject.lock();
		}
		~YScopedLock()
		{
			m_lockedObject.unlock();
		}
	};

#define SCOPED_LOCK(lockedObject) ysimple_system::YScopedLock<decltype(lockedObject)>(lockedObject)

	struct YSIMPLESYSTEM_EXPORTS_API YCriticalSection
	{
		CRITICAL_SECTION	m_critical_section;

		YCriticalSection();
		~YCriticalSection();

	private:
		void	lock();
		void	unlock();
		
		template <class U> friend class YScopedLock;
	};

}